package com.changgou.seckill.mq;


import com.alibaba.fastjson.JSON;
import com.changgou.seckill.service.SeckillOrderService;
import entity.SeckillStatus;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "seckillQueue")
public class DelaySeckillMessageListener {

    @Autowired
    private SeckillOrderService seckillOrderService;

    @RabbitHandler
    public void getMessage(String message){
        //获取用户排队信息
        SeckillStatus seckillStatus = JSON.parseObject(message, SeckillStatus.class);
        //如果此时redis中没有用户排队信息，则表明该订单已经处理，如果有用户排队信息，则表明用户尚未支付，关闭订单，关闭微信支付
        if (seckillStatus!= null){
            //关闭微信支付
            //这里需要自己做，之前写过这里暂时不实现
            //关闭订单  删除订单
        seckillOrderService.closeOrder(seckillStatus.getUsername());
        }
    }
}
